import 'package:daoyi_ui_admin_getx/app/routes/app_pages.dart';
import 'package:daoyi_ui_admin_getx/app/widgets/common_image_widget.dart';
import 'package:daoyi_ui_admin_getx/generated/locales.g.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

const loginRegisterStyle = TextStyle(
  fontSize: 18,
  color: Colors.white,
);

class MineHeaderWidget extends StatelessWidget {
  const MineHeaderWidget({super.key});

  Widget _notLoginBuilder(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(
        left: 10,
        right: 10,
      ),
      decoration: BoxDecoration(
        color: context.theme.appBarTheme.backgroundColor,
      ),
      height: 95,
      child: Row(
        children: [
          const SizedBox(
            height: 65,
            width: 65,
            child: CircleAvatar(
              backgroundColor: Colors.white,
              child: CommonImageWidget("static/default-avatar.png"),
            ),
          ),
          const SizedBox(width: 10),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  GestureDetector(
                    onTap: () {
                      Get.toNamed(Routes.LOGIN);
                    },
                    child: Text(
                      LocaleKeys.buttons_login.tr,
                      style: loginRegisterStyle,
                    ),
                  ),
                  const Text(
                    "/",
                    style: loginRegisterStyle,
                  ),
                  GestureDetector(
                    onTap: () {
                      Get.toNamed(Routes.REGISTER);
                    },
                    child: Text(
                      LocaleKeys.buttons_sign_in.tr,
                      style: loginRegisterStyle,
                    ),
                  ),
                ],
              ),
              const Text(
                "登陆后可以享受更多功能",
                style: TextStyle(
                  color: Colors.white,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  Widget _loginBuilder(BuildContext context) {
    String username = 'admin';
    String nickname = '兰陵王';
    int userId = 102;
    String avatar = 'static/login-avatar.png';
    return GestureDetector(
      onTap: () {
        Get.toNamed(Routes.USER_PROFILE);
      },
      child: Container(
        padding: const EdgeInsets.only(
          left: 10,
          right: 10,
        ),
        decoration: BoxDecoration(
          color: context.theme.appBarTheme.backgroundColor,
        ),
        height: 95,
        child: Row(
          children: [
            SizedBox(
              height: 65,
              width: 65,
              child: CircleAvatar(
                backgroundColor: Colors.white,
                child: CommonImageWidget(avatar),
              ),
            ),
            const SizedBox(width: 10),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    nickname,
                    style: loginRegisterStyle,
                  ),
                  Text(
                    "ID.：$userId",
                    style: const TextStyle(
                      color: Colors.white,
                    ),
                  ),
                  Text(
                    "账号：$username",
                    style: const TextStyle(
                      color: Colors.white,
                    ),
                  ),
                ],
              ),
            ),
            const Icon(
              Icons.qr_code,
              color: Colors.white,
              size: 18,
            ),
            const SizedBox(width: 20),
            const Icon(
              Icons.arrow_forward_ios,
              color: Colors.white,
              size: 14,
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    var isLogin = true;
    return isLogin ? _loginBuilder(context) : _notLoginBuilder(context);
  }
}
